package com.itboye.sunsun.person.fragments;

import java.util.List;

import com.itboye.sunsun.MainActivity;
import com.itboye.sunsun.R;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.PersonDataBean;
import com.itboye.sunsun.beans.OrderBean.DetailBean;
import com.itboye.sunsun.beans.OrderBean.InnerDetailBean;
import com.itboye.sunsun.beans.OrderDetailBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.controller.LoginController;
import com.itboye.sunsun.controller.LoginedState;
import com.itboye.sunsun.custome.XExpandableListView.IXListViewListener;
import com.itboye.sunsun.login.ui.LoginActivity;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.custome.XListView;
import com.itboye.sunsun.person.adapter.PayActivityAdapter;
import com.itboye.sunsun.person.adapter.ReceiveActivityAdapter;
import com.itboye.sunsun.person.adapter.SendActivityAdapter;
import com.itboye.sunsun.support.BaseActivity;
import com.itboye.sunsun.utils.DebugLog;
import com.itboye.sunsun.utils.DebugToast;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.volley.CodeErrorException;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ReceiveActivity extends BaseActivity implements OnClickListener{
	
	private XListView xlistview;
	private List<InnerDetailBean>dataList;
	private ReceiveActivityAdapter adapter;
	private RelativeLayout backrela;
	private TextView name;
	private TextView mobile;
	private TextView location;
	private View top;
	private Button dial;
	private View middle;
	private String id;
	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.activity_receiveactivity);
		
		Intent intent=getIntent();
		dataList=intent.getExtras().getParcelableArrayList("list");
		id=intent.getStringExtra("goodsid");
		goodsDetail(id);
		initView();
		initData();
		
		//DebugToast.show(dataList.size(),0);
	}
	public void initView()
	{
		top=LayoutInflater.from(App.ctx).inflate(R.layout.receivelistview_headerview_top, null);
		middle=LayoutInflater.from(App.ctx).inflate(R.layout.paylistview_headerview_middle, null);
		name=(TextView) middle.findViewById(R.id.name);
		mobile=(TextView) middle.findViewById(R.id.mobile);
		location=(TextView) middle.findViewById(R.id.location);
	}
	public void initData()
	{
		adapter=new ReceiveActivityAdapter(dataList, App.ctx);
		xlistview.setAdapter(adapter);
		xlistview.addHeaderView(top);
		xlistview.addHeaderView(middle);
		xlistview.setPullRefreshEnable(false);
		xlistview.setPullLoadEnable(false);
	}
	@Override
	public void onClick(View v) {
		if(v.getId()==R.id.backrela)
		{
			this.finish();
		}if(v.getId()==R.id.dial)
		{
			Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+"0580-8253177"));
			startActivity(intent);
		}
		
	}
	
	public void goodsDetail(String id)
	{
		MyJsonRequest<OrderDetailBean> request = new MyJsonRequest.Builder<OrderDetailBean>().apiVer("100")
				.typeKey("BY_Orders_detail")
				.param("id", id)
				.requestListener(new XRequestListener<OrderDetailBean>() {

					@Override
					public void onResponse(OrderDetailBean response) {
						// TODO Auto-generated method stub
						name.setText("收货人"+":"+response.getContactname());
						mobile.setText(""+response.getMobile());
						String city=response.getCity();
						String area=response.getarea();
						if(city.equals("市辖区")||city.equals("县"))
						{
							city="";
						}else if(area.equals("市辖区"))
						{
							area="";
						}
						location.setText("收货地址："+response.getProvince()+city+area+response.getDetailinfo());


					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code, String msg) {
						if (exception instanceof CodeErrorException) {
							Toast.makeText(App.ctx, msg, 0).show();
						} else {
							Toast.makeText(App.ctx, exception.toString(), 0).show();
						}

					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}




}
